import { useUserStore } from '@/stores/user.js';

const permission = {
    mounted(el, binding) {
        const { value: requiredPerms } = binding
        if (!hasPermission(requiredPerms)) {
            el.parentNode?.removeChild(el) // 直接移除DOM元素
        }
    }
}

// 检查权限逻辑
const hasPermission = (requiredPerms) => {
    const userStore = useUserStore();
    let userPerms = userStore.permissionCodes
    if (Array.isArray(requiredPerms)) {
        return requiredPerms.some(perm => userPerms.includes(perm))
    }
    return userPerms.includes(requiredPerms)
}

export { permission, hasPermission }